package com.zeekr.rocketmq.controller;


import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.zeekr.rocketmq.dto.UserDTO;
import com.zeekr.rocketmq.producer.MyProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangyuanping
 */
@RestController
@RequestMapping("/test")
public class ProducerController {

    @Autowired
    private MyProducer myProducer;

    @PostMapping("/send/mess/sync")
    public String sendSyncMess(@RequestBody UserDTO dto){
        myProducer.sendSyncMessage("demo-topic", JSONUtil.toJsonStr(dto));
        return StrUtil.EMPTY;
    }
    @PostMapping("/send/mess/async")
    public String sendAsyncMess(@RequestBody UserDTO dto){
        myProducer.sendAsyncMessage("demo-topic", JSONUtil.toJsonStr(dto));
        return StrUtil.EMPTY;
    }
    @PostMapping("/send/mess/order")
    public String sendOrderMess(@RequestBody UserDTO dto){
        myProducer.sendOrderMessage("demo-topic", JSONUtil.toJsonStr(dto));
        return StrUtil.EMPTY;
    }
    @PostMapping("/send/mess/delayed")
    public String sendDelayedMess(@RequestBody UserDTO dto){
        myProducer.sendDelayedMessage("demo-topic", JSONUtil.toJsonStr(dto));
        return StrUtil.EMPTY;
    }
    @PostMapping("/send/mess/batch")
    public String sendBatchMess(@RequestBody UserDTO dto){
        myProducer.sendBatchMessage("demo-topic", JSONUtil.toJsonStr(dto));
        return StrUtil.EMPTY;
    }
}
